package pl.prv.polanie.client.dto;

import java.util.Comparator;

import com.google.gwt.user.client.rpc.IsSerializable;


public class CSVSubjectEventDTO extends java.lang.Object implements IsSerializable, ICSVDTO {


    // Fields    

	private long id;
     /**
      *  0 - zajecia odbywaja sie w kazdym tygodniu
      *  1 - parzysty (dolny lewy) 
      *  2 - nieparzysty (gorny prawy)
      */ 
     private int eventSort;
     private String subject;
     private String room;
     private String subgroup;
     private String lecturer;
     private String calendarDay;
     private Integer startTime;
     private Integer duration;
     
     //nie biora udzial w sortowaniu
     private String subjectNameName;
     private String subjectNameSymbol;
     private String subjectTypeName;
     private String subjectTypeInitial;
     
     private String lecturerName;
     private String lecturerSurname;
     private String lecturerAcademicTitle;
     
     
     private boolean highlighted;

     public static final int SORT_CONST__ID = 0;
     public static final int SORT_CONST__SUBJECT = 1;
     public static final int SORT_CONST__LECTURER = 2;
     public static final int SORT_CONST__ROOM = 3;
     public static final int SORT_CONST__SUBGROUP = 4;
     public static final int SORT_CONST__CALENDAR_DAY = 5;
     public static final int SORT_CONST__START_TIME = 6;
     public static final int SORT_CONST__DURATION = 7;

//     public static final int SORT_CONST__SUBJECT_NAME_NAME = 1;
//     public static final int SORT_CONST__SUBJECT_NAME_SYMBOL = 2;
//     public static final int SORT_CONST__SUBJECT_TYPE_NAME = 3;


     
    // Constructors


	public CSVSubjectEventDTO(long id, int eventSort, String subject, String room,
			String subgroup, String lecturer, String calendarDay,
			Integer startTime, Integer duration, String subjectNameName,
			String subjectNameSymbol, String subjectTypeName, String subjectTypeInitial,
			String lecturerName, String lecturerSurname, String lecturerAcademicTitle
			) {
		super();
		this.id = id;
		this.eventSort = eventSort;
		this.subject = subject;
		this.room = room;
		this.subgroup = subgroup;
		this.lecturer = lecturer;
		this.calendarDay = calendarDay;
		this.startTime = startTime;
		this.duration = duration;
		
		this.subjectNameName = subjectNameName;
		this.subjectNameSymbol = subjectNameSymbol;
		this.subjectTypeName = subjectTypeName;
		this.subjectTypeInitial = subjectTypeInitial;
		
		this.lecturerName = lecturerName;
		this.lecturerSurname = lecturerSurname;
		this.lecturerAcademicTitle = lecturerAcademicTitle;
	}
	
	
	/** default constructor */
	public CSVSubjectEventDTO() {
	}
	
	
	public String toString() {
		String result = "" +
			"[ " + CSVSubjectEventDTO.class + "]" +
			" id: " + id +
			", eventSort: " + eventSort +
			", subject: " + subject +
			", room: " + room +
			", subgroup: " + subgroup +
			", lecturer: " + lecturer +
			", calendarDay: " + calendarDay +
			", startTime: " + startTime +
			", duration: " + duration; 
		return result;
	}
	
	
	public int getEventSort() {
		return eventSort;
	}
	
	
	public void setEventSort(int eventSort) {
		this.eventSort = eventSort;
	}
	
	
	public String getSubject() {
		return subject;
	}
	
	
	public void setSubject(String subject) {
		this.subject = subject;
	}
	
	
	public String getRoom() {
		return room;
	}
	
	
	public void setRoom(String room) {
		this.room = room;
	}
	
	
	public String getSubgroup() {
		return subgroup;
	}
	
	
	public void setSubgroup(String subgroup) {
		this.subgroup = subgroup;
	}
	
	
	public String getLecturer() {
		return lecturer;
	}
	
	
	public void setLecturer(String lecturer) {
		this.lecturer = lecturer;
	}
	
	
	public String getCalendarDay() {
		return calendarDay;
	}
	
	
	public void setCalendarDay(String calendarDay) {
		this.calendarDay = calendarDay;
	}
	
	
	public Integer getStartTime() {
		return startTime;
	}
	
	
	public void setStartTime(Integer startTime) {
		this.startTime = startTime;
	}
	
	
	public Integer getDuration() {
		return duration;
	}
	
	
	public void setDuration(Integer duration) {
		this.duration = duration;
	}
	
	
	public long getId() {
		return id;
	}
	
	
	public void setId(long id) {
		this.id = id;
	}


	public boolean isHighlighted() {
		return highlighted;
	}


	public void setHighlighted(boolean highlighted) {
		this.highlighted = highlighted;
	}
	
	public String getField(int col) {
		if (col == SORT_CONST__ID) {
			return "" + getId();
		} else if (col == SORT_CONST__SUBJECT) {
			return "" + getSubject();
		} else if (col == SORT_CONST__ROOM) {
			return "" + getRoom();
		} else if (col == SORT_CONST__SUBGROUP) {
			return "" + getSubgroup();
		} else if (col == SORT_CONST__LECTURER) {
			return "" + getLecturer();
		} else if (col == SORT_CONST__CALENDAR_DAY) {
			return "" + getCalendarDay();
		} else if (col == SORT_CONST__START_TIME) {
			return "" + getStartTime();
		} else if (col == SORT_CONST__DURATION) {
			return "" + getDuration();
		}
		return "no field";
	}
	
	
	
	public static Comparator getComparator(final int colIndex) {
		Comparator cmp = new Comparator() {
			public int compare(Object o1, Object o2) {

			    final int BEFORE = -1;
			    final int EQUAL = 0;
			    final int AFTER = 1;
			    
			    CSVSubjectEventDTO obj1;
			    CSVSubjectEventDTO obj2;
			    if (o1 instanceof CSVSubjectEventDTO && o2 instanceof CSVSubjectEventDTO) {

					obj1 = (CSVSubjectEventDTO) o1;
					obj2 = (CSVSubjectEventDTO) o2;
					
					//this optimization is usually worthwhile, and can
					//always be added
					if ( obj1 == obj2 ) return EQUAL;

					//primitive numbers follow this form
					if (colIndex == SORT_CONST__ID) {
						Long l1 = new Long(obj1.getId());
						Long l2 = new Long(obj2.getId());
						return l1.compareTo(l2);
					} else if (colIndex == SORT_CONST__SUBJECT) {
						return obj1.getSubject().compareTo(obj2.getSubject());
					} else if (colIndex == SORT_CONST__LECTURER) {
						return obj1.getLecturer().compareTo(obj2.getLecturer());
					} else if (colIndex == SORT_CONST__ROOM) {
						return obj1.getRoom().compareTo(obj2.getRoom());
					} else if (colIndex == SORT_CONST__SUBGROUP) {
						return obj1.getSubgroup().compareTo(obj2.getSubgroup());
					} else if (colIndex == SORT_CONST__CALENDAR_DAY) {
						return obj1.getCalendarDay().compareTo(obj2.getCalendarDay());
					} else if (colIndex == SORT_CONST__START_TIME) {
						return obj1.getStartTime().compareTo(obj2.getStartTime());
					} else if (colIndex == SORT_CONST__DURATION) {
						return obj1.getDuration().compareTo(obj2.getDuration());
					}
					
				};
				return EQUAL;
			}
		};

		return cmp;
	}


	public String getSubjectNameName() {
		return subjectNameName;
	}


	public void setSubjectNameName(String subjectNameName) {
		this.subjectNameName = subjectNameName;
	}


	public String getSubjectNameSymbol() {
		return subjectNameSymbol;
	}


	public void setSubjectNameSymbol(String subjectNameSymbol) {
		this.subjectNameSymbol = subjectNameSymbol;
	}


	public String getSubjectTypeName() {
		return subjectTypeName;
	}


	public void setSubjectTypeName(String subjectTypeName) {
		this.subjectTypeName = subjectTypeName;
	}


	public String getSubjectTypeInitial() {
		return subjectTypeInitial;
	}


	public void setSubjectTypeInitial(String subjectTypeInitial) {
		this.subjectTypeInitial = subjectTypeInitial;
	}


	public String getLecturerName() {
		return lecturerName;
	}


	public void setLecturerName(String lecturerName) {
		this.lecturerName = lecturerName;
	}


	public String getLecturerSurname() {
		return lecturerSurname;
	}


	public void setLecturerSurname(String lecturerSurname) {
		this.lecturerSurname = lecturerSurname;
	}


	public String getLecturerAcademicTitle() {
		return lecturerAcademicTitle;
	}


	public void setLecturerAcademicTitle(String lecturerAcademicTitle) {
		this.lecturerAcademicTitle = lecturerAcademicTitle;
	}
	

	
	
	
	
	/*
    public static final int SORT_CONST__ID = 0;
    public static final int SORT_CONST__SUBJECT = 1;
    public static final int SORT_CONST__LECTURER = 2;
    public static final int SORT_CONST__ROOM = 3;
    public static final int SORT_CONST__SUBGROUP = 4;
    public static final int SORT_CONST__CALENDAR_DAY = 5;
    public static final int SORT_CONST__START_TIME = 6;
    public static final int SORT_CONST__DURATION = 7;
	*/
}